/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.fragment.nativeview;

import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.demo.fragment.BaseMaterialFragment;
import it.gmariotti.cardslib.library.cards.ProgressCard;
import it.gmariotti.cardslib.library.cards.actions.BaseSupplementalAction;
import it.gmariotti.cardslib.library.cards.actions.IconSupplementalAction;
import it.gmariotti.cardslib.library.cards.actions.TextSupplementalAction;
import it.gmariotti.cardslib.library.cards.material.MaterialLargeImageCard;
import it.gmariotti.cardslib.library.view.CardView;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;

import java.util.ArrayList;

/**
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class NativeMaterialCardFragment extends BaseMaterialFragment {

    public static final int SIMULATED_REFRESH_LENGTH = 3000;
    ProgressCard progressCard;

    @Override
    protected int getSubTitleHeaderResourceId() {
        return ResourceTable.String_header_title_subtitle_ex_material;
    }

    @Override
    protected int getTitleHeaderResourceId() {
        return ResourceTable.String_header_title_group1;
    }

    @Override
    protected String getDocUrl() {
        return null;
    }

    @Override
    protected String getSourceUrl() {
        return "";
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_demo_fragment_native_materialcard);
        initCards();
    }

    private void initCards() {
        init_largeimage();
        init_largeimage_text();

        //initProgressCard();
    }


    /**
     * Builds a Material Card with Large Image and Text
     */
    private void init_largeimage_text() {

        ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>();

        // Set supplemental actions
        TextSupplementalAction t1 = new TextSupplementalAction(this, ResourceTable.Id_text1);
        t1.setOnActionClickListener((card, view) -> new ToastDialog(getContext()).setText(" Click on Text SHARE ").show());
        actions.add(t1);

        TextSupplementalAction t2 = new TextSupplementalAction(this, ResourceTable.Id_text2);
        t2.setOnActionClickListener((card, view) -> new ToastDialog(getContext()).setText(" Click on Text LEARN ").show());
        actions.add(t2);

        //Create a Card, set the title over the image and set the thumbnail
        MaterialLargeImageCard card =
                MaterialLargeImageCard.with(this)
                        .setTextOverImage("Italian Beaches")
                        .setTitle("This is my favorite local beach")
                        .setSubTitle("A wonderful place")
                        .useDrawableId(ResourceTable.Media_sea)
                        .setupSupplementalActions(ResourceTable.Layout_carddemo_native_material_supplemental_actions_large, actions)
                        .build();

        card.setClickedListener((card1, view) -> new ToastDialog(getContext()).setText(" Click on ActionArea ").show());

        //Set card in the CardView
        CardView cardView = (CardView) this.findComponentById(ResourceTable.Id_carddemo_largeimage_text);
        cardView.setCard(card);
    }

    /**
     * Builds a Material Card with Large and small icons as supplemental actions
     */
    private void init_largeimage() {

        // Set supplemental actions as icon
        ArrayList<BaseSupplementalAction> actions = new ArrayList<BaseSupplementalAction>();
        IconSupplementalAction t1 = new IconSupplementalAction(this, ResourceTable.Id_ic1);
        t1.setOnActionClickListener((card, view) -> new ToastDialog(getContext()).setText(" Click on Text SHARE ").show());
        actions.add(t1);

        IconSupplementalAction t2 = new IconSupplementalAction(this, ResourceTable.Id_ic2);
        t2.setOnActionClickListener((card, view) -> new ToastDialog(getContext()).setText(" Click on Text LEARN  ").show());
        actions.add(t2);

        MaterialLargeImageCard card =
                MaterialLargeImageCard.with(this)
                        .setTextOverImage("Italian Beaches")
                        .useDrawableId(ResourceTable.Media_im_beach)
                        .setupSupplementalActions(ResourceTable.Layout_carddemo_native_material_supplemental_actions_large_icon, actions)
                        .build();

        card.setClickedListener((card1, view) -> new ToastDialog(getContext()).setText(" Click on ActionArea").show());

        //Set card in the CardView
        CardView cardView = (CardView) this.findComponentById(ResourceTable.Id_carddemo_largeimage);
        cardView.setCard(card);
    }

}
